package com.jiepos.mpos.biz.operationlog.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jiepos.mpos.common.constant.DBConstant.Table;
import com.jiepos.mpos.common.dao.AppModifyHistoryDao;
import com.jiepos.mpos.common.entity.App_Modify_HistoryEntity;
import com.jiepos.mpos.core.entity.Pagination;
import com.jiepos.mpos.core.service.BaseService;
import com.jiepos.mpos.core.util.StringUtils;

@Service
public class SysLogService extends BaseService {

	@Autowired
	private AppModifyHistoryDao  appModifyHistoryDao;
	
	/**
	 * 获取系统操作日志Json
	 * @param pagination
	 * @param request
	 * @param app_Modify_HistoryEntity
	 * @return
	 */
	public Map getSystemLogList(Pagination pagination,HttpServletRequest request,App_Modify_HistoryEntity app_Modify_HistoryEntity){
		StringBuffer sb = this.getInitSql("T1");
		List<String> list = new ArrayList<>();
		sb.append(", T1.HISTORY_UUID, T1.SYSTEM_TYPE,T1.SYSTEM_KEY,T1.COLUMN_NM,T1.OLD_DATA,T1.NEW_DATA,T1.USER_IP from ");
		sb.append(Table.T_APP_MODIFY_HISTORY).append(" t1 where 1=1 ");
		if(!StringUtils.isBlank(app_Modify_HistoryEntity.getSystem_type())){
			sb.append(" and t1.system_type like ?");
			list.add("%"+app_Modify_HistoryEntity.getSystem_type()+"%");
		}
		if(!StringUtils.isBlank(app_Modify_HistoryEntity.getSystem_key())){
			sb.append(" and t1.system_key like ?");
			list.add("%"+app_Modify_HistoryEntity.getSystem_key()+"%");
		}
		pagination.queryString = sb.toString();
		pagination = this.getOrderSql(pagination, "t1");
		return appModifyHistoryDao.getPaginationMap(pagination, "t1", list);
	}
}
